package com.lhq.business.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lhq.business.domain.BookTag;
import com.lhq.business.mapper.BookTagMapper;
import com.lhq.business.service.IBookTagService;
import com.lhq.common.core.base.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 图书标签对应Service业务层处理
 *
 * @author lhq
 * @date 2024-05-11
 */
@Service
public class BookTagServiceImpl  extends BaseServiceImpl<BookTagMapper,BookTag>  implements IBookTagService
{
    @Autowired
    private BookTagMapper bookTagMapper;

    /**
     * 查询图书标签对应
     *
     * @param bookId 图书标签对应主键
     * @return 图书标签对应
     */
    @Override
    public BookTag selectById(String bookId)
    {
        return bookTagMapper.selectById(bookId);
    }

    /**
     * 查询图书标签对应分页列表
     * @return 图书标签对应
     */
    @Override
    public IPage<BookTag> selectList(Page<BookTag> page,BookTag bookTag)
    {
        QueryWrapper<BookTag> queryWrapper =new QueryWrapper<>();
        return bookTagMapper.selectPage(page,queryWrapper);
    }

    /**
     * 新增图书标签对应
     *
     * @param bookTag 图书标签对应
     * @return 结果
     */
    @Transactional
    @Override
    public int insertBookTag(BookTag bookTag)
    {
        return bookTagMapper.insert(bookTag);
    }

    /**
     * 修改图书标签对应
     *
     * @param bookTag 图书标签对应
     * @return 结果
     */
    @Transactional
    @Override
    public int updateBookTag(BookTag bookTag)
    {
        return bookTagMapper.updateById(bookTag);
    }

    /**
     * TODO 待做
     * 删除图书标签对应信息
     *
     * @param bookId 图书标签对应主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteByBookId(Long bookId)
    {
        BookTag  bookTag =new BookTag();
        bookTag.setBookId(bookId);
        return bookTagMapper.update(bookTag,Wrappers
                .lambdaUpdate(BookTag.class)
                .eq(BookTag::getBookId, bookId)
                .set(BookTag::getDelFlag, "1"));
    }
}
